library(knitr)
if (is_latex_output()) {
  knitr_figs_dir <- "knitr-figs-pdf/"
  knitr_cache_dir <- "knitr-cache-pdf/"
  fig_out_type <- "png"
} else {
  knitr_figs_dir <- "knitr-figs-docx/"
  knitr_cache_dir <- "knitr-cache-docx/"
  fig_out_type <- "png"
}
fig_asp <- 0.618
fig_width <- 9
fig_out_width <- "6in"
fig_dpi <- 180
fig_align <- "center"
fig_pos <- "htb"
opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  comment = "#>",
  fig.path = knitr_figs_dir,
  cache.path = knitr_cache_dir,
  fig.asp = fig_asp,
  fig.width = fig_width,
  out.width = fig_out_width,
  echo = FALSE,
  #  autodep = TRUE,
  #  cache = TRUE,
  cache.comments = FALSE,
  dev = fig_out_type,
  dpi = fig_dpi,
  fig.align = fig_align,
  fig.pos = fig_pos
)
# add other packages here:
library(dplyr)
library(readr)
library(tibble)
library(rosettafish)
library(csasdown)
options(
  # Prevent xtable from adding a timestamp comment to the table code it produces
  xtable.comment = FALSE,
  # Do not allow kableExtra to load packages, we add them manually in csasdown
  kableExtra.latex.load_packages = FALSE,
  # Stop chunk output (echo) running into the margins
  width = 80,
  # Do not use scientific notation (stops tables from showing 1.2e3, etc.)
  scipen = 999)

meta <- rmarkdown::metadata
meta_out <- rmarkdown::metadata$output
csl <- "csl/csas.csl"
options(OutDec = ".")
if (is.null(getOption("french"))) {
  stop("`french` was not set up correctly in YAML header in index.Rmd. ",
       "It must be true or false",
       call. = FALSE)
}
if (getOption("french")) {
  csl <- "csl/csas-french.csl"
  options(OutDec = ",")
}
# This hook simplifies document translation for the author.
# When building in French, it draws a box around paragraphs contained in chunks
#  which have the option `needs_trans = TRUE`. It also labels
#  the box with a "Needs translation" tag in red and the chunk label in blue.
# You need to change the `needs_trans` option to `FALSE` for a chunk once you
#  have inserted the translated text into it. You will get a utf-8 error if
#  you leave it as `TRUE` and there is French in the chunk.
#  This function assumes you are translating from English to French.
#  If you wrote your document in French and want to translate to English,
#  put a ! before `getOption("french")` below and add the `need_trans`
#  chunk options to your English paragraph chunks instead of the French ones.
#  
#  IMPORTANT NOTES
#  - Use `csasdown::render_resdoc()` to render the document. This runs a
#    pre-processing step which ensures any inline R chunks
#    `r print("Like this one")` are taken care of correctly and that all
#    backslash variables (eg. \pi, \alpha, \@ref, \cite) are all processed
#    correctly.
#  - French latex places a space before the colon by default so if you need a colon
#    with no space before it, use \\hc .
knit_hooks$set(needs_trans = function(before, options){
  if(getOption("french") && options$needs_trans){
    if (before){
      paste0("\\
   \\begin{lrbox}{\\userinput}
   \\begin{minipage}{\\dimexpr\\linewidth-2\\fboxsep-2\\fboxrule}
   \\textcolor{red}{\\textbf{Needs translation - \\textcolor{blue}{knitr chunk: ", options$label, "}}}
   \\begin{lstlisting}
  ")
    } else {
      "
   \\end{lstlisting}
   \\end{minipage}
   \\end{lrbox}
   \\noindent
   \\fbox{\\usebox{\\userinput}}
  "
    }
  }
})

title: r ifelse(fr(), meta$french_title, meta$title) month: r ifelse(fr(), meta$french_month, meta$month) region: r ifelse(fr(), meta$french_region, meta$region) csl: r csl


options(
  # Prevent xtable from adding a timestamp comment to the table code it produces
  xtable.comment = FALSE,
  # Do not allow kableExtra to load packages, we add them manually in csasdown
  kableExtra.latex.load_packages = FALSE,
  # Stop chunk output (echo) running into the margins
  width = 80,
  # Do not use scientific notation (stops tables from showing 1.2e3, etc.)
  scipen = 999)

meta <- rmarkdown::metadata
meta_out <- rmarkdown::metadata$output
csl <- "csl/csas.csl"
options(OutDec = ".")
if (is.null(getOption("french"))) {
  stop("`french` was not set up correctly in YAML header in index.Rmd. ",
       "It must be true or false",
       call. = FALSE)
}
if (getOption("french")) {
  csl <- "csl/csas-french.csl"
  options(OutDec = ",")
}
# This hook simplifies document translation for the author.
# When building in French, it draws a box around paragraphs contained in chunks
#  which have the option `needs_trans = TRUE`. It also labels
#  the box with a "Needs translation" tag in red and the chunk label in blue.
# You need to change the `needs_trans` option to `FALSE` for a chunk once you
#  have inserted the translated text into it. You will get a utf-8 error if
#  you leave it as `TRUE` and there is French in the chunk.
#  This function assumes you are translating from English to French.
#  If you wrote your document in French and want to translate to English,
#  put a ! before `getOption("french")` below and add the `need_trans`
#  chunk options to your English paragraph chunks instead of the French ones.
#  
#  IMPORTANT NOTES
#  - Use `csasdown::render_resdoc()` to render the document. This runs a
#    pre-processing step which ensures any inline R chunks
#    `r print("Like this one")` are taken care of correctly and that all
#    backslash variables (eg. \pi, \alpha, \@ref, \cite) are all processed
#    correctly.
#  - French latex places a space before the colon by default so if you need a colon
#    with no space before it, use \\hc .
knit_hooks$set(needs_trans = function(before, options){
  if(getOption("french") && options$needs_trans){
    if (before){
      paste0("\\
   \\begin{lrbox}{\\userinput}
   \\begin{minipage}{\\dimexpr\\linewidth-2\\fboxsep-2\\fboxrule}
   \\textcolor{red}{\\textbf{Needs translation - \\textcolor{blue}{knitr chunk: ", options$label, "}}}
   \\begin{lstlisting}
  ")
    } else {
      "
   \\end{lstlisting}
   \\end{minipage}
   \\end{lrbox}
   \\noindent
   \\fbox{\\usebox{\\userinput}}
  "
    }
  }
})

title: r ifelse(fr(), meta$french_title, meta$title) month: r ifelse(fr(), meta$french_month, meta$month) region: r ifelse(fr(), meta$french_region, meta$region) csl: r csl


Context

The scientific basis for assessing the status of American Lobster (Homarus americanus) in Lobster Fishing Area (LFA) 35 was examined at an assessment framework review meeting in September 2019, followed by an assessment of the status of the Lobster resources in LFA 35 in October 2019 (DFO 2021a), a Stock Status Update in August 2020 (DFO 2021b), and again in September 2021 (DFO 2022). One primary indicator and three secondary indicators that describe changes in Lobster abundance and biomass were defined, and reference points for the primary indicator were proposed. A suite of indicators is applied in this update from the 2019 framework review to update the stock status to the end of the 2020–2021 fishing season, wherever possible.

This Science Response Report results from the Regional Science Response Process of September ##, 2022 on the Stock Status Update of American Lobster in Lobster Fishing Area (LFA) 35.

Background

Description of the fishery

Commercial Lobster fishing in LFA 35 occurs in the Bay of Fundy (Figure 1) and borders the biggest Lobster fishery in the Canadian Northwest Atlantic, LFA 34, which has the highest landings and the most participants of any LFA in Canada. Landings in LFA 35 began a long-term increase in the mid-1990s, and current landings are near a record high. A similar increase in landings was also observed in most of the Gulf of Maine regions and other LFAs in Atlantic Canada. The fishery is managed by input controls including a Minimum Legal Size (MLS, 82.5 mm Carapace Length [CL]), prohibition on landing of both egg-bearing and V-notched females (with no setal hairs), limited entry licensing, split fishing season (October 14th–December 31st; last day of February–July 31st), and trap limits (300). Other management measures include the requirement of vents to allow sub-legal-size Lobster to escape and biodegradable trap mechanisms to mitigate ghost fishing by lost traps.

knitr::include_graphics("BOFLFA.png")
setwd("C:/Users/HowseVJ/Documents/GitHub/bio.lobster/inst/Updates/LFA35-38/LFA35_Update Markdown")

require(rgdal)
require(devtools)
require(roxygen2)
require(geosphere)
require(SpatialHub)
require(lubridate)
require(bio.utilities)
require(bio.lobster)
require(rstanarm)
require(rlang)
require(glue)
require(PBSmapping)


    p = bio.lobster::load.environment()
    la()
    assessment.year = 2022 ##Check Year
    p$syr = 1989
  p$yrs = p$syr:assessment.year



figdir = file.path("LFA35_Update Markdown")

        p$lfas = c("35") # specify lfa



logs=lobster.db("process.logs")
land =lobster.db("annual.landings")
Sland = lobster.db('seasonal.landings')

Analysis and Response

Indicators of Stock Status

The stock status of the Lobster in LFA 35 is assessed using primary, secondary, and contextual indicators. This update includes the primary indicator that is used to define stock status in relation to reference points defined in Cook et al. (In press.1) and secondary indicators that display time-series trends but do not have reference points. The data sources available for establishing indicators for LFA 35 come from both fishery-dependent and fishery-independent data sources. Fishery-dependent data consist of commercial logbooks that report information on date, location (grid), effort, and estimated catch. The fishery-independent data sources are from the DFO Maritimes Region Summer Research Vessel Survey (herein RV survey).

Something about the challenges with Survey?

Primary Indicator

In LFA 35, there is one primary indicator for stock status that describes the time-series trends relative to reference points. The primary indicator for describing stock status is standardized commercial Catch Per Unit Effort (CPUE). There is currently no primary indicator of fishing pressure or exploitation.

Catch Per Unit Effort

Commercial catch rates are a preferred indicator over landings, as they are standardized to account for the level of fishing effort. This is especially important in effort-controlled fisheries. The commercial fishing data used in the estimation of catch rates were obtained from mandatory logbooks that were put in place in the mid-2000s. It has been well documented that trap-based catch rates vary throughout a fishing season due to factors other than available biomass. These factors include fishing behavior, localized depletion, and environmental conditions (Drinkwater et al. 2006). In an effort to account for these factors, CPUE data were standardized through generalized linear modelling with explanatory variables of Year, Day of Season, Temperature, and the interaction between Day of Season and Temperature. Year was treated as a factor rather than a continuous variable to reduce any constraints from inter-annual variability.

Model predictions were made for day 1 of the fishing season at the median day 1 temperature across all years. The available time series covers the current high-productivity period and a lower-productivity period from 2006–2010 (Figure 2). The median of the high-productivity period (2011–2018) was used as the proxy for the biomass at carrying capacity (K). Following the recommendations of DFO (2009), the Upper Stock Reference (USR) and Limit Reference Point (LRP) were set to 40% and 20% of the K proxy. A 3-year running median is used to compare the standardized CPUE to the USR and LRP. This value will dampen the impact of any anomalous years that may occur due to factors outside of changes in abundance.

    logs=lobster.db("process.logs")
    TempModelling = TempModel( annual.by.area=F, redo.data=F)
            CPUE.data<-CPUEModelData(p,redo=T,TempModelling)

            mf1 = formula(logWEIGHT ~ fYEAR + DOS + TEMP + DOS * TEMP)

            CPUE.data<- CPUEModelData(p,redo=F)
            t=with(subset(CPUE.data,DOS==1),tapply(TEMP,LFA,mean))

            pData=list()

            CPUEModelResults = list()

            for(i in 1:length( p$lfas)){

                mdata = subset(CPUE.data,LFA==p$lfas[i]&SYEAR%in%p$yrs)
                if(nrow(mdata)>10){
                CPUEModelResults[[i]] = CPUEmodel(mf1,mdata,t=t[i],d=1)
                pData[[i]]=CPUEModelResults[[i]]$pData
                pData[[i]]$LFA=p$lfas[i]
            }
            }

            names(CPUEModelResults) = p$lfas

            CPUEindex=do.call("rbind",pData)




    l35 = subset(CPUEindex,LFA==35,c("YEAR","mu"))
    k = median(l35$mu[which(l35$YEAR %in% 2011:2018)])
    usr = .4*k
    lrp = .2*k


plot(l35$YEAR,l35$mu,xlab='Year',ylab=' Standardized CPUE (kg/TH)',type='p',pch=16,ylim=c(0,6),xlim=c(2005,2022))
    running.median = with(rmed(l35$YEAR,l35$mu),data.frame(YEAR=yr,running.median=x))
    l35=merge(l35,running.median,all=T)
    lines(l35$YEAR,l35$running.median,col='blue',lty=1,lwd=3)
    points(l35$YEAR[nrow(l35)],l35$mu[nrow(l35)], type='b', pch=24,bg='blue')
    abline(h=usr,col='green',lwd=2,lty=2)
    abline(h=lrp,col='red',lwd=2,lty=3)

dev.off()

The trend in CPUE indicates that an increase in stock biomass occurred between 2005 and 2012 (Figure ##). The CPUE has remained high (more than twice the USR) since 2011. The 3-year running median for CPUE for the 2022 season is ## kg per Trap Haul (kg/TH), which is above the USR (1.97 kg/TH) and LRP (0.98 kg/TH).

The CPUE for ### is preliminary due to outstanding logs; as of ### the monthly reporting rate was between ##% to ##% by month.

Secondary Indicators

Secondary indicators represent time-series trends that are tracked individually, without defined reference points. The secondary indicators for LFA 35 include the LFA-specific landings and total effort, as well as recruit abundance, commercial biomass, and relative fishing mortality estimates from the RV survey of the Bay of Fundy region (Strata 484, 490–495). Scallop survey recruit abundance is not included in this update as the survey was not conducted in 2020, and it was not yet completed for the 2021 season at the time of this update.

Landings and Effort

Commercial landings are related to population biomass, as fishery controls are input- (effort controls) rather than output-based (total allowable catch). There are many factors that can affect this relationship, including changes in fishing effort, catchability (including the effects of environment, gear efficiency), Lobster size distribution, and the spatial overlap between distribution of Lobster and effort.

Fishing effort, recorded as the number of Trap Hauls (THs), in the Lobster fishery is controlled by fishing season length, trap limits, and limited number of fishing licences. Consequently, there is a maximum fishing effort that can be deployed; however, this maximum is never met because factors such as weather conditions, seasonally variable catch rates, and fishing partnerships limit the total number of THs. Total fishing effort is calculated from mandatory logbooks. Figure ## has been updated to include the preliminary data for the 2020–2021 fishing season and effort has been corrected to address an error in the 2020 stock status update (DFO 2021b). Effort in the corresponding figure was calculated incorrectly due to the use of the wrong calibration.

a=lobster.db('process.logs')
a = subset(a,LFA==35)
b=aggregate(cbind(NUM_OF_TRAPS,WEIGHT_KG)~SYEAR,data=a,FUN=sum)
b$CPUE=b$WEIGHT_KG/b$NUM_OF_TRAPS
h=lobster.db('seasonal.landings.redo')
h=lobster.db('seasonal.landings')
h
h=h[,c('SYEAR','LFA35')]
h
h$SYEAR=1976:2022
merge(b,h)
g=merge(b,h)
g$EFF = g$LFA35/g$CPUE




par(mar=c(5.1, 4.1, 4.1, 5.1),las=1)

plot(g$SYEAR,g$LFA35,xlab='Year',ylab='Landings(t)',type='h',ylim=c(0,max(g$LFA35)*1.2),pch=15,col='grey',lwd=10,lend=3)
lines(g$SYEAR[nrow(g)],g$LFA35[nrow(g)],type='h',pch=21,col='steelblue4',lwd=10,lend=3)
par(new=T)

plot(g$SYEAR,g$EFF,ylab='',xlab='', type='b', pch=16, axes=F,ylim=c(0,max(g$EFF,na.rm=T)))
points(g$SYEAR[nrow(g)],g$EFF[nrow(g)], type='b', pch=24,bg='black')
axis(4)
mtext("Effort ('000s Trap Hauls)", 4, 3.5, outer = F,las=0) 
dev.off()       


subsamp<-g[g$SYEAR >2009 & g$SYEAR <2023,]
range(subsamp$LFA35)
median(subsamp$LFA35)

DFO RV Survey Commercial Biomass and Recruit Abundance

Despite strata boundaries having significant overlap with LFA 35–38, there were few (< 20 per year) sets within each LFA, suggesting that the value of indicators derived from these data was limited. Extending the commercial survey biomass index to years prior to 1999, when size information was not collected, was performed using the ratio of commercial to total biomass estimated between 1999 and 2018 (0.746). The time series of commercial biomass showed a pulsed increase from 2000 to 2004, with a variable, but increasing, trend from 2010 to 2018; however, survey catch rates in the last two years were the lowest in the last 10 years (Figure ???). The size-at-maturity for Lobster in the Bay of Fundy is substantially greater than the MLS, and, as such, the commercial biomass available post-fishery will constitute those individuals entering the spawning population in the upcoming year. Data from the 2021 RV survey were not available, Figures 6, 7 and 8 only include results up to the end of the 2020 survey.

RV survey recruit abundance (70–82 mm CL) exhibits a similar pattern to the total abundance, with increases from 2010 to 2013, followed by variable catch rates at a substantially higher level than has been observed in the time series (Figure 7).

Relative Fishing Mortality

Relative fishing mortality (relF) uses both the RV survey commercial biomass estimates and landings to show the changes in removals (Ct) relative to the survey indices (It). As the RV survey occurs after the fishery is complete, the estimation of relF was adjusted by the landings as:

(ADD EQUATION)

Assuming that survey catchabilities were constant and the index of commercial biomass was proportional to true commercial biomass, relF is an index of fishing mortality (F). The estimates of relF reflect the variation in the commercial biomass index, with decreases between the late 1990s and early 2000s ,

(ADD Mention of the decrease in the 1980s)

increases to 2010, then decreases to 2013 with variable, but low, estimates of relF since 2013 (Figure 6). Tracking the relF for the Bay of Fundy provides a depiction of the patterns observed across the larger area.

require(bio.survey)
require(bio.lobster)

p = bio.lobster::load.environment()
p$libs = NULL
ff = "LFA35-38Assessment"
fp1 = file.path(project.datadirectory('bio.lobster'),"analysis",ff)
fpf1 = file.path(project.figuredirectory('bio.lobster'),ff)
dir.create(fpf1,showWarnings=F)
dir.create(fp1,showWarnings=F)

p$yrs = 1970:2022
p1 = p


stratifiedAnalysesCommercial = function( p=p1, survey,lfa, fpf = fpf1, fp = fp1,f=ff,wd=10,ht=8){
    p$series =c('summer')# p$series =c('georges');p$series =c('fall')
    p$years.to.estimate = p$yrs
    p$length.based = T
    p$by.sex = T
    p$size.class = c(83,300)
    p$sex = c(1,2)
    p$bootstrapped.ci=T
    p$strata.files.return=F
    p$vessel.correction.fixed=1.2
    p$strat = NULL
    p$clusters = c( rep( "localhost", 7) )
    p$strata.efficiencies = F
    p = make.list(list(yrs=p$years.to.estimate),Y=p)
    p$define.by.polygons = T
    p$lobster.subunits=F
    p$area = lfa
    p$reweight.strata = T #this subsets 

    aout= dfo.rv.analysis(DS='stratified.estimates.redo',p=p)
    write.csv(aout,file=file.path(fpf, paste(lfa,'DFOCommB.csv')))

      p$add.reference.lines = F
    p$time.series.start.year = p$years.to.estimate[1]
    p$time.series.end.year = p$years.to.estimate[length(p$years.to.estimate)]
    p$metric = 'weights' #weights
    p$measure = 'stratified.total' #'stratified.total'
    p$figure.title = ""
    p$reference.measure = 'median' # mean, geomean
    p$file.name =  file.path(f,paste(lfa,'DFOrestratifiedtotalweightscommercial.png',sep=""))

    p$y.maximum = NULL # NULL # if ymax is too high for one year
    p$show.truncated.weights = F #if using ymax and want to show the weights that are cut off as values on figure

    p$legend = FALSE
    p$running.median = T
    p$running.length = 3
    p$running.mean = F #can only have rmedian or rmean
     p$error.polygon=F
    p$error.bars=T
    require(bio.lobster)
     p$ylim2 = NULL
    xx = aggregate(ObsLobs~yr,data=aout,FUN=sum)
    names(xx) =c('x','y')
     p$ylim=NULL
     ref.out= figure.stratified.analysis(x=aout,out.dir = 'bio.lobster', p=p,wd=wd,ht=ht)
     return(aout)
  }



aout = stratifiedAnalysesCommercial(survey='DFO',lfa='LFA35-38')
write.csv(aout,file.path(fp1,'LFA3538CommercialB.csv'))
require(bio.survey)
require(bio.lobster)
require(lubridate)
require(devtools)
require(bio.utilities)
require(PBSmapping)
la()
p = bio.lobster::load.environment()
p$libs = NULL
ff = "LFA35-38Assessment"
fp1 = file.path(project.datadirectory('bio.lobster'),"analysis",ff)
fpf1 = file.path(project.figuredirectory('bio.lobster'),ff)
dir.create(fpf1,showWarnings=F)
dir.create(fp1,showWarnings=F)
p1 = p
p1$yrs = 1970:2022

stratifiedAnalyses = function(p=p1, survey,lfa, fpf = fpf1, fp = fp1,f=ff,wd=10,ht=8){
                p$series =c('summer')
                p$define.by.polygons = T
                p$lobster.subunits=F
                p$area = lfa
                p$years.to.estimate = p$yrs[-1]
                p$length.based = F
                p$by.sex = F
                p$bootstrapped.ci=T
                p$strata.files.return=F
                p$vessel.correction.fixed=1.2
                p$strat = NULL
                p$clusters = c( rep( "localhost", 7) )
                p$strata.efficiencies = F
                p = make.list(list(yrs=p$years.to.estimate),Y=p)
                p$reweight.strata = T #this subsets 


      aout= dfo.rv.analysis(DS='stratified.estimates.redo',p=p)
      write.csv(aout,file=file.path(fpf, paste(lfa,'DFOtotalabund.csv')))


                              p$add.reference.lines = F
                              p$time.series.start.year = p$years.to.estimate[1]
                              p$time.series.end.year = p$years.to.estimate[length(p$years.to.estimate)]
                              p$metric = 'numbers' #weights
                              p$measure = 'stratified.mean' #'stratified.total'
                              p$figure.title = ""
                              p$reference.measure = 'median' # mean, geomean
                              p$file.name = file.path(f,paste(lfa,'DFOrestratifiednumbers.png',sep=""))

                          p$y.maximum = NULL # NULL # if ymax is too high for one year
                        p$show.truncated.numbers = F #if using ymax and want to show the numbers that are cut off as values on figure

                                p$legend = FALSE
                                p$running.median = T
                                p$running.length = 3
                                p$running.mean = F #can only have rmedian or rmean
                               p$error.polygon=F
                              p$error.bars=T

                               p$ylim=NULL
                      if(lfa == 'LFA35-38') p$ylim=c(0,150)
                       p$box=T
                       p$file.name = file.path(f,paste(lfa,'DFOrestratifiednumbersNOY.png', sep=""))
                       ref.out=   figure.stratified.analysis(x=aout,out.dir = 'bio.lobster', p=p,wd=wd,ht=ht)

                       p$box=T
                        p$ylim=NULL
                       p$metric = 'weights'
                       p$file.name = file.path(f,paste(lfa,'DFOrestratifiedweightsNOY.png',sep=""))
                       ref.out=   figure.stratified.analysis(x=aout,out.dir = 'bio.lobster', p=p,wd=wd,ht=ht)

                       p$box=NULL
                       p$ylim=NULL
                       p$file.name = file.path(f,paste(lfa,'DFOrestratifiedDWAO.png',sep=""))
                       p$metric = 'dwao'
                       ref.out=   figure.stratified.analysis(x=aout,out.dir = 'bio.lobster', p=p,wd=wd,ht=ht)

                       p$file.name = file.path(f,paste(lfa,'DFOrestratifiedgini.png',sep=""))
                       p$metric = 'gini'
                       p$ylim =c(0,1)
                       ref.out=   figure.stratified.analysis(x=aout,out.dir = 'bio.lobster', p=p,wd=wd,ht=ht)
                       p$ylim = NULL
                       return(aout)
        }


a = stratifiedAnalyses(survey='DFO',lfa='LFA35-38')
require(bio.survey)
require(bio.lobster)
require(lubridate)
require(devtools)
require(bio.utilities)
require(PBSmapping)
la()
p = bio.lobster::load.environment()
p$libs = NULL
ff = "LFA35-38Assessment"
fp1 = file.path(project.datadirectory('bio.lobster'),"analysis",ff)
fpf1 = file.path(project.figuredirectory('bio.lobster'),ff)
dir.create(fpf1,showWarnings=F)
dir.create(fp1,showWarnings=F)
p1 = p
p1$yrs = 1970:2022

stratifiedAnalysesRecruits = function(p=p1, survey,lfa, fpf = fpf1, fp = fp1,f=ff,wd=10,ht=8){
      p$series =c('summer')# p$series =c('georges');p$series =c('fall')
      p$area = lfa
      p$years.to.estimate = p$yrs
      p$length.based = T
      p$by.sex = T
      p$size.class = c(70,82)
      p$sex = c(1,2)
      p$bootstrapped.ci=T
      p$strata.files.return=F
      p$vessel.correction.fixed=1.2
      p$strat = NULL
      p$clusters = c( rep( "localhost", 7) )
      p$strata.efficiencies = F
      p = make.list(list(yrs=p$years.to.estimate),Y=p)
      p$define.by.polygons = T
      p$lobster.subunits=F
      p$reweight.strata = T #this subsets 

    aout= dfo.rv.analysis(DS='stratified.estimates.redo',p=p)
     write.csv(aout,file=file.path(fpf, paste(lfa,'DFOrecruits.csv')))

                        p$add.reference.lines = F
                              p$time.series.start.year = p$years.to.estimate[1]
                              p$time.series.end.year = p$years.to.estimate[length(p$years.to.estimate)]
                              p$metric = 'numbers' #numbers
                              p$measure = 'stratified.mean' #'stratified.total'
                              p$figure.title = ""
                              p$reference.measure = 'median' # mean, geomean
                              p$file.name =  file.path(f,paste(lfa,'DFOrestratifiednumbersrecruits.png',sep=""))
                          p$y.maximum = NULL # NULL # if ymax is too high for one year
                        p$show.truncated.numbers = F #if using ymax and want to show the numbers that are cut off as values on figure
                                p$legend = FALSE
                                p$running.median = T
                                p$running.length = 3
                                p$running.mean = F #can only have rmedian or rmean
                               p$error.polygon=F
                              p$error.bars=T
                      if(lfa == 'LFA35-38') p$ylim = c(0,80)
                      p$file.name =  file.path(f,paste(lfa,'NOYDFOrestratifiednumbersrecruits.png',sep=""))
                      ref.out=   figure.stratified.analysis(x=aout,out.dir = 'bio.lobster', p=p,wd=wd,ht=ht)
            }

stratifiedAnalysesRecruits(survey='DFO',lfa='LFA35-38')
require(bio.lobster)
require(PBSmapping)

a = lobster.db('annual.landings')
b = lobster.db('seasonal.landings')
ff = "LFA35-38Assessment"

b$YR = substr(b$SYEAR,6,9)
a = subset(a,YR<1976)
b = subset(b,YR>1975 & YR<=2022)
fpf1 = file.path(project.figuredirectory('bio.lobster'),ff)
fp1 = file.path(project.datadirectory('bio.lobster'),"analysis",ff)

LFA = c('LFA35','LFA36','LFA38')
for(i in LFA){
        aa = a[,c('YR',i)]
        bb = b[,c('YR',i)]
        aa = (rbind(aa,bb))
        aa = aa[order(aa$YR),]
        file.name = paste('Landings',i,'.png',sep="")
        png(file=file.path(fpf1,'LandingsL3538.png'),units='in',width=15,height=12,pointsize=18, res=300,type='cairo')
        plot(aa$YR,aa[,i],type='h',lwd=4,col='black',xlab='Year',ylab='Landings (t)')
        lines(aa$YR,runmed(aa[,i],3),col='salmon',lwd=3)
        dev.off()
        }



df2 = read.csv(file.path(fpf1,'LFA35-38 DFOCommB.csv'))
df =  read.csv(file.path(fpf1,'LFA35-38 DFOtotalabund.csv'))
df = subset(df,yr<1999)
df2 = subset(df2,yr>1998)
df = as.data.frame(rbind(df,df2))
df = df[,c('yr','w.Yst','w.ci.Yst.l','w.ci.Yst.u')] #proportion of total weight that is commercial
df$w.Yst[which(df$yr<1999)] <- df$w.Yst[which(df$yr<1999)]*0.746
df$w.ci.Yst.l[which(df$yr<1999)] <- df$w.ci.Yst.l[which(df$yr<1999)]*0.746
df$w.ci.Yst.u[which(df$yr<1999)] <- df$w.ci.Yst.u[which(df$yr<1999)]*0.746



     with(df,plot(yr,w.Yst,pch=1,xlab='Year',ylab='Commerical Biomass (t)',ylim=c(0,9500)))
     with(df,arrows(yr,y0=w.ci.Yst.u,y1=w.ci.Yst.l, length=0))
     with(subset(df,yr>1998),points(yr,w.Yst,pch=16))
     xx = rmed(df$yr,df$w.Yst)
     xx = as.data.frame(do.call(cbind,xx))
     with(subset(xx,yr<1999),lines(yr,x,col='salmon',lwd=1))
     with(subset(xx,yr>1998),lines(yr,x,col='salmon',lwd=3))
     dev.off()

a$L3538 = rowSums(a[,12:14])
b$L3538 = rowSums(b[,4:6])
c358 = as.data.frame(rbind(a[,c('YR','L3538')],b[,c('YR','L3538')]))
names(c358)[1] = 'yr'
df  =merge(df,c358)
df$rL = df$L3538/(df$w.ci.Yst.l+df$L3538)
df$rU =df$L3538/ (df$w.ci.Yst.u+df$L3538)
df$rM = df$L3538/(df$w.Yst+df$L3538)


     png(file=file.path(fpf1,'LFA3538RelFDFO.png'),units='in',width=10,height=8,pointsize=18, res=300,type='cairo')
        plot(df$yr,df$rM,type='p',pch=16,col='black',xlab='Year',ylab='Relative F')
        arrows(df$yr,y0 = df$rL,y1 = df$rU,length=0)
        with(rmed(df$yr,df$rM),lines(yr,x,col='salmon',lwd=3))
dev.off()

Conclusions

Since 2011, LFA 35 has been in a high-productivity period and, as of 2020, the primary indicator of stock status, CPUE, shows a positive signal for LFA 35 and remains well above the USR. Given the reporting rate for landings is currently between 36% and 86% by month, annual landings appear to be on track. As of 2020, there has been an increase in total, commercial, and recruit abundance. Between 2018 and 2019, however, a large decline was evident in both commercial biomass and recruit abundance. In 2020, these values were marginally higher than 2019, but they are well below the highs observed between 2012 and 2018. Across most of the indicators (CPUE, commercial biomass, and recruit abundance), the productivity of the last two years was low compared to 2012–2018. The LFA 35 Lobster stock continues to be in a productive period and is currently in the Healthy Zone.

Contributors

Mandatory section and title.

contributors <- tibble::tribble(
  ~Name,          ~Affiliation,
  "Victoria Howse",   "DFO Science, Maritimes Region",
  "John Smith",   "DFO Science, Maritimes Region",
)
csasdown::csas_table(contributors)

\MakeApproval

Sources of information

Optional for regular Science Responses, and mandatory for Stock Status Updates as these must include the citation for the peer-reviewed Science Advisory Report.



LobsterScience/bio.lobster documentation built on Feb. 14, 2025, 3:28 p.m.